<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3" xmlns:head="http://www.w3.org/1999/html">
<head th:include="public/public_css::public_css ('ASN收货')"/>
<body style="background-color: #f2f2f2;">
<div class="layui-fluid larry-wrapper">
    <div class="layui-card">
        <div class="layui-row layui-col-space30">
            <div class="layui-col-xs24">
                <form class="layui-form layui-card-header  layui-card-header-auto" id="searchForm">
                    <div class="layui-inline">
                        <label class="layui-form-label">供应商名称</label>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" name="gysmc"/>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">ASN编号</label>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" name="asnbh"/>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">PO编号</label>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" name="dycgdbh"/>
                        </div>
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label">ASN状态</label>
                        <select name="asnzt" lay-filter="aihao">
                            <option value="" selected="">全部</option>
                            <option value="0">初始</option>
                            <option value="1">部分收货</option>
                            <option value="2">完全收货</option>
                            <option value="3">订单取消</option>
                            <option value="4">订单完成</option>
                        </select>
                    </div>

                    <div class="layui-inline inline-search-btn">
                        <a class="layui-btn layui-btn-normal" data-type="reload">搜索</a>
                    </div>

                    <div class="moreSearch" style="display: none">

                        <div class="layui-inline">
                            <label class="layui-form-label">创建开始时间</label>
                            <div class="layui-input-inline">
                                <input type="text" class="layui-input" name="stime" id="test5"
                                       placeholder="yyyy-MM-dd"/>
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label"> </label>
                            <div class="layui-input-inline" style="height:20px">
                                --
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label">创建结束时间</label>
                            <div class="layui-input-inline">
                                <input type="text" class="layui-input" name="etime" id="test6" placeholder="yyyy-MM-dd"/>
                            </div>
                        </div>

                    </div>
                </form>

                <div class="moreBtn"><i class="layui-icon layui-icon-triangle-d" style="color: #1E9FFF;"></i></div>

                <!--列表-->
                <section class="panel panel-padding layui-card-body">
                    <div class="pro">
                        <table id="table" class="table text-nowrap"></table>
                    </div>
                </section>
            </div>
        </div>
    </div>
</div>
</body>


<div th:include="public/public_js::public_js"></div>
<style type="text/css">

</style>
<script>
    $("form input[type=text]").each(function () {
        this.value = $.trim(this.value);

        $(document).ready(function () {//通用方法去输入框前后空格
            $("form").on("change", function () {
                $("form input[type=text]").each(function () {
                    this.value = $.trim(this.value);
                });
            })
        });
    });

    console.log("我来了！！ ");
    $(".moreBtn").on("click",function () {
        $(".moreSearch").toggle();
    })
    layui.use(['list', 'layer', 'zzpUtils', 'jquery', 'laydate'], function () {
        var zzpUtils = layui.zzpUtils,
            $ = layui.jquery,
            laydate = layui.laydate;
        zzpUtils.select2({
            elem: ".js-data-example-ajax",
            url: "/wmsrrailwayplatform/list"
        });
        window.operateEvent = {
            "click .layui-btn-primary": function (e, value, row, index) {
                alert(row.mc);
            },
            "click #Confirmation": function (e, value, row, index) {//确认收货
                ConfirmationDialog(row.id);
            },
            "click #Partial": function (e, value, row, index) {//部分收货
                PartialDialog(row.id);
            },
            "click #delete": function (e, value, row, index) {//删除
                deleteDialog(row.id);
            }
        };

        //取消收货
        function deleteDialog(id) {
            var ids = [];
            ids.push(id);
                zzpUtils.dialog({
                    title: "取消收货",
                    type: 2,
                    content: "/AsnCollect/delete?id=" + ids,
                    area: ['55%', '55%'], //设置dialog大小，也可以不设置，
                    end: function () {//修改成功后刷新
                        zzpUtils.refreshTable("#table");
                    }
                });
        }

        //	回车查询
        document.onkeydown = function (event) {
            e = event ? event : (window.event ? window.event : null);
            if (e.keyCode == 13) {
                //执行的方法
                $('#search_button').click();
            }
        };

        //创建时间开始
        laydate.render({
            elem: '#test5'
            , theme: '#20a0ff',
        });
        //创建时间结束
        laydate.render({
            elem: '#test6'
            , theme: '#20a0ff',
        });
        laydate.render({
            elem: '#test5'
            , theme: '#20a0ff'
        });
        var $table = zzpUtils.table({
            elem: '#table',
            isApi: true,
            pagination: true,
            url: '/wmsEstimatedArrivalOrder/seachASNReceiving',
            columns: [ {
                field: 'ckmc',
                title: '仓库'
            }, {
                field: 'hzmc',
                title: '货主'
            }, {
                field: 'asnbh',
                title: 'ASN编号'
            }, {
                field: 'show_asnlx',
                title: 'ASN类型'
            }, {
                field: 'show_asnzt',
                title: 'ASN状态'
            }, {
                field: 'show_yxj',
                title: '优先级'
            }, {
                field: 'yjdhsjks',
                title: '预计到货时间'
            }, {
                field: 'cjsj',
                title: '创建时间'
            }, {
                field: 'show_shzt',
                title: '审核状态'
            }, {
                field: 'pobh',
                title: '关联PO编号'
            }, {
                field: 'zdr',
                title: '制单人'
            }, {
                field: 'ddshr',
                title: '审核人'
            }, {
                field: 'show_dyzt',
                title: '打印状态'
            }, {
                field: 'dysj',
                title: '打印时间'
            }, {
                field: 'shwcsj',
                title: '收货完成时间'
            }, {
                field: 'gysmc',
                title: '供应商名称'
            }, {
                field: 'show_mpzt',
                title: '码盘状态'
            }, {
                field: 'caozuo',
                title: '操作',
                events: operateEvent,
                formatter: operateFormatter
            }],
            queryParams: function () {//查询条件
                return zzpUtils.getFormJson($("#searchForm"));
            },
            detailFormatter: function (index, row) {
                return "这里就没有确定过11";
            },
        });


        //确认收货
        function ConfirmationDialog(id) {
            /*alert(id)*/
                zzpUtils.dialog({
                    title: "确认收货",
                    type: 2,
                    content: "/AsnCollect/confirm?id=" + id,
                    area: ['100%', '100%'], //设置dialog大小，也可以不设置，
                    end: function () {//修改成功后刷新
                        zzpUtils.refreshTable("#table");
                    }
                });
        }

        //部分收货
        function PartialDialog(id) {
            zzpUtils.dialog({
                title: "部分收货",
                type: 2,
                content: "/AsnCollect/Asnbftz?id=" + id,
                area: ['100%', '100%'], //设置dialog大小，也可以不设置，
                end: function () {//修改成功后刷新
                    zzpUtils.refreshTable("#table");
                }
            });
        }

        $("#delBtn").on('click', function () {
            var $rows = $table.bootstrapTable('getSelections');
            if ($rows.length == 0) {
                layer.msg("请选择一条进行删除");
            } else {
                /*var ids = new Array()*/
                var ids = $.map($rows, function (row) {
                    return row.id;
                })
                zzpUtils.dialog({
                    title: "取消收货",
                    type: 2,
                    content: "/AsnCollect/delete?id=" + ids,
                    area: ['55%', '55%'], //设置dialog大小，也可以不设置，
                    end: function () {//修改成功后刷新
                        zzpUtils.refreshTable("#table");
                    }
                });
                /*alert(ids.join(','));*/
            }
        })

        function operateFormatter(value, row, index) {

            if (row.asnzt==0){
                return [
                    '<a class="layui-btn layui-btn-normal layui-btn-xs" id="Confirmation">确认收货</a>'
                ].join('')
            }if (row.asnzt==1){
                return [
                    '<a class="layui-btn layui-btn-normal layui-btn-xs" id="Partial">部分收货</a>',
                    '<a class="layui-btn layui-btn-danger layui-btn-xs" id="delete">取消收货</a>'
                ].join('')
            }if (row.asnzt==2 ){
                return [
                    '<a class="layui-btn layui-btn-danger layui-btn-xs" id="delete">取消收货</a>'
                ].join('')
            }/*if (row.asnzt==4){
                return [
                    '<a class="layui-btn layui-btn-danger layui-btn-xs" id="delete">取消收货</a>'
                ].join('')
            }*/

        }

        $(".inline-search-btn").on('click', function () {
            zzpUtils.refreshTable("#table");
        })
    });
</script>
</html>